public class PAService implements IceBox.Service
{
    public void
    start(String name, Ice.Communicator communicator, String[] args)
    {
	Boolean persistence = true;

	Ice.Properties properties = communicator.getProperties();
	Ice.ObjectPrx subscriber;

	String aux1 = properties.getProperty("persistence");
	String camera = properties.getProperty("camera");
	String index = properties.getProperty("index");
	String video_topic_name = properties.getProperty("video_topic");

	if (aux1.equals("no"))
	    persistence = false;

        _adapter = communicator.createObjectAdapter("PAServiceAdapter." + camera + "." + index);
	subscriber = _adapter.add(new PAI(communicator, persistence),
				  communicator.stringToIdentity("pa"));

	System.out.println(".....");
	System.out.println("Subscribing with the event channel...");
	System.out.println(".....");

	IceGrid.QueryPrx query = IceGrid.QueryPrxHelper.checkedCast(communicator.stringToProxy("IceGrid/Query"));
	IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(query.findObjectById(communicator.stringToIdentity("Oculus.IceStorm/TopicManager")));

	//
        // Retrieve the topic.
        //
        IceStorm.TopicPrx topic = null;
        try {
	    topic = manager.retrieve(video_topic_name);
	}
        catch(IceStorm.NoSuchTopic e) {
            try {
		topic = manager.create(video_topic_name);
	    }
            catch(IceStorm.TopicExists ex) {
                System.err.println(": temporary failure, try again.");
		System.exit(-1);
            }
        } // Fin catch NoSuchTopic.
	
	java.util.Map<String, String> qos = new java.util.HashMap<String, String>();
	qos.put("reliability", "ordered");

	try {
	    topic.subscribeAndGetPublisher(qos, subscriber);
	    System.out.println(subscriber.toString() + " is now subscribed!");
	}
        catch(IceStorm.AlreadySubscribed e) {
	    System.out.println(subscriber.toString() + " was already subscribed!");
        }
        catch(IceStorm.BadQoS e) {
            e.printStackTrace();
        }

        _adapter.activate();
    }

    public void
    stop()
    {
        _adapter.destroy();
    }

    private Ice.ObjectAdapter _adapter;
}